package com.agent.vpsserver.modules.server.controller;


import com.agent.vpsserver.common.dto.AdminAccountTokenDTO;
import com.agent.vpsserver.common.dto.BaseRequestDTO;
import com.agent.vpsserver.common.dto.PageBean;
import com.agent.vpsserver.common.dto.Result;
import com.agent.vpsserver.modules.server.manager.SmsManager;
import com.agent.vpsserver.modules.server.request.SmsGetContentRequest;
import com.agent.vpsserver.modules.server.request.SmsGetNumberRequest;
import com.agent.vpsserver.modules.server.request.SmsInfoPageRequest;
import com.agent.vpsserver.modules.server.request.SmsUpdateStatusRequest;
import com.agent.vpsserver.modules.server.response.*;
import com.agent.vpsserver.modules.server.service.SmsInfoService;
import com.baomidou.mybatisplus.extension.api.ApiController;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 短信信息(SmsInfo)表控制层
 *
 * @author guochao
 * @since 2024-03-29 12:02:28
 */
@RestController
@RequestMapping("api/smsInfo")
@AllArgsConstructor
public class SmsInfoController extends ApiController {

    private final SmsInfoService smsInfoService;
    private final SmsManager smsManager;

    @PostMapping(value = "/page")
    @ApiOperation(value = "分页")
    public Result<PageBean<SmsInfoPageResponse>> page(@RequestBody @Valid SmsInfoPageRequest request) {
        return Result.success(smsInfoService.pageData(request));
    }

    @PostMapping(value = "/generate")
    @ApiOperation(value = "生成手机号唯一编码")
    public Result<SmsInfoGenerateResponse> generate(@RequestBody @Valid AdminAccountTokenDTO request) {
        SmsInfoGenerateResponse response = smsManager.generate();
        return Result.success(response);
    }

    @PostMapping(value = "/getBuyInfo")
    @ApiOperation(value = "获取购买信息")
    public Result<List<SmsGetBuyInfoResponse>> getBuyInfo(@RequestBody @Valid BaseRequestDTO request) {
        List<SmsGetBuyInfoResponse> response = smsManager.getBuyInfo();
        return Result.success(response);
    }

    @PostMapping(value = "/getNumber")
    @ApiOperation(value = "获取手机号")
    public Result<SmsGetNumberResponse> getNumber(@RequestBody @Valid SmsGetNumberRequest request) {
        SmsGetNumberResponse response = smsManager.getNumber(request);
        return Result.success(response);
    }

    @PostMapping(value = "/updateStatus")
    @ApiOperation(value = "修改状态")
    public Result<Boolean> updateStatus(@RequestBody @Valid SmsUpdateStatusRequest request) {
        smsManager.updateStatus(request);
        return Result.success(Boolean.TRUE);
    }

    @PostMapping(value = "/getContent")
    @ApiOperation(value = "获取短信内容")
    public Result<SmsGetContentResponse> getContent(@RequestBody @Valid SmsGetContentRequest request) {
        SmsGetContentResponse response = smsManager.getContent(request);
        return Result.success(response);
    }
}

